package com.managementemployees.adapter;

import java.util.ArrayList;

import com.managementemployees.activities.R;
import com.managementemployees.model.NhanVien;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class NhanVienAdapter extends BaseAdapter {

	private String TAG = "NhanVienAdapter";
	private ArrayList<NhanVien> mArrayList = new ArrayList<>();
	private Context mContext;
	private TextView txtId;
	private TextView txtTen;
	private TextView txtGioiTinh;
	private TextView txtNgaySinh;
	private TextView txtIdCongViec;

	public NhanVienAdapter(ArrayList<NhanVien> arr, Context context) {
		super();
		Log.d(TAG, "HungND NV mArr " + arr.size());
		this.mArrayList = arr;
		this.mContext = context;

	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		Log.d(TAG, "HungND getCount " + mArrayList.size());
		return mArrayList.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return mArrayList.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return mArrayList.get(arg0).getId();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup viewGroup) {
		// TODO Auto-generated method stub
		Log.d(TAG, "HungND NV1 " + mArrayList.size());
		LayoutInflater inflater = (LayoutInflater) mContext
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.custom_item_nhanvien, null);
			// viewHolder = new ViewHolder();
			txtId = (TextView) convertView.findViewById(R.id.txtIdNv);
			txtTen = (TextView) convertView.findViewById(R.id.txtTen);
			txtGioiTinh = (TextView) convertView.findViewById(R.id.txtGioiTinh);
			txtNgaySinh = (TextView) convertView.findViewById(R.id.txtNgaySinh);
			// convertView.setTag(viewHolder);
		} else {
			// viewHolder = (ViewHolder) convertView.getTag();
		}

		NhanVien nv = mArrayList.get(position);
		Log.d(TAG, "HungND NV2 " + nv.getTenNV());
		txtId.setText(nv.getId() + "");
		txtTen.setText(nv.getTenNV());
		txtGioiTinh.setText(nv.getGioiTinh());
		txtNgaySinh.setText(nv.getNgaySinh());
		
		return convertView;
	}

}
